class TempExaminationResoultsController < ApplicationController
  
  # GET /temp_examination_resoults/1/edit
  def check
    @new_examination_resoult = TempExaminationResoult.find(params[:id])
  end

  def confirm
    @temp_examination_resoult = TempExaminationResoult.find(params[:id])
    logger.debug "params " + params[:id]
    @examination_resoult = ExaminationResoult.create(
      :order_examination_id => @temp_examination_resoult.order_examination_id,
      :description =>  @temp_examination_resoult.description
    )
    for p in @temp_examination_resoult.param_resoults
      ParamResoult.create(
        :examination_resoult_id => @examination_resoult.id,
        :param_norm_id => p.param_norm_id,
        :description => p.description,
        :resoult => p.resoult
      )
    end
    TempExaminationResoult.delete(params[:id])
    
    #    format.html { redirect_to(@temp_examination_resoult) }
    #    format.html { redirect_to :id => @examination_resoult.id, :controller => 'ExaminationResoults', :action => 'show'}
    #    format.xml  { head :ok }

  end

  def decline

  end

  # GET /temp_examination_resoults
  # GET /temp_examination_resoults.xml
  def index
    @temp_examination_resoults = TempExaminationResoult.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @temp_examination_resoults }
    end
  end

  # GET /temp_examination_resoults/1
  # GET /temp_examination_resoults/1.xml
  def show
    @temp_examination_resoult = TempExaminationResoult.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @temp_examination_resoult }
    end
  end

  # POST /temp_examination_resoults
  # POST /temp_examination_resoults.xml
  def create
    @temp_examination_resoult = TempExaminationResoult.new(params[:temp_examination_resoult])

    respond_to do |format|
      if @temp_examination_resoult.save
        flash[:notice] = 'TempExaminationResoult was successfully created.'
        format.html { redirect_to(@temp_examination_resoult) }
        format.xml  { render :xml => @temp_examination_resoult, :status => :created, :location => @temp_examination_resoult }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @temp_examination_resoult.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /temp_examination_resoults/1
  # PUT /temp_examination_resoults/1.xml
  def update
    @temp_examination_resoult = TempExaminationResoult.find(params[:id])
    respond_to do |format|
      if @temp_examination_resoult.update_attributes(params[:temp_examination_resoult])
        flash[:notice] = 'TempExaminationResoult was successfully updated.'
        format.html { redirect_to(@temp_examination_resoult) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @temp_examination_resoult.errors, :status => :unprocessable_entity }
      end
    end
    if(params[:confirm_button])
      confirm
    else if(params[:decline_button])
        decline
      end
    end
  end

  # DELETE /temp_examination_resoults/1
  # DELETE /temp_examination_resoults/1.xml
  def destroy
    @temp_examination_resoult = TempExaminationResoult.find(params[:id])
    @temp_examination_resoult.destroy

    respond_to do |format|
      format.html { redirect_to(temp_examination_resoults_url) }
      format.xml  { head :ok }
    end
  end
end
